package com.example.taobao;

import androidx.annotation.DrawableRes;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {
    private ListView listView;
    private List<Goods> goodsList = new ArrayList<>();
    private GoodsAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initGoods();
        adapter = new GoodsAdapter(MainActivity.this,R.layout.good_item,goodsList);
        listView = (ListView) findViewById(R.id.list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                Intent intent = new Intent(MainActivity.this,MainActivity2.class);
                intent.putExtra("position",position);
                startActivity(intent);
            }
        });
    }

    private void initGoods() {
        for(int i=0;i<2;i++){
            Goods goods1 = new Goods("【2020款】Apple/苹果13英寸1.4GHz新款MacBook Pro ",R.drawable.mac,
                    "4核 | i5处理器 | 256GB固态硬盘","￥13888",
                    "2270人累计付款","深圳 >");
            goodsList.add(goods1);
            Goods goods2 = new Goods("2020新款Apple/苹果Mac Mini 国行迷你小主机电脑M1定制",R.drawable.mini,
                    "4核 | i5处理器 | 256GB固态硬盘","￥8288",
                    "1005人累计付款","深圳 >");
            goodsList.add(goods2);
            Goods goods3 = new Goods("苹果/Apple Mac Pro定制台式机塔式服务器主机电脑工作站",R.drawable.pro,
                    "16核 | i9处理器 | 2TB固态硬盘","￥129999",
                    "12人累计付款","广州 >");
            goodsList.add(goods3);
            Goods goods4 = new Goods("Apple/苹果 Apple Watch Series 6",R.drawable.watch,
                    "蓝色铝金属表壳 | 深海军蓝色运动型表带 | 超长待机","￥3599",
                    "1.5万人累计购买","Apple官方旗舰店 北京 >");
            goodsList.add(goods4);
        }
    }

}
